﻿using coremvcdemo.Helper;
using coremvcdemo.Services;
using Microsoft.AspNetCore.Mvc;

namespace coremvcdemo.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        private readonly ILoginService service;

        public LoginController(ILoginService service)
        {
            this.service = service;
        }

        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult<Dictionary<string, object>> getlogin(loginModel model)
        {
            return service.getlogin(model, HttpContext.Session);
        }
        [HttpGet]
        public Dictionary<string, object> getUserMsg()
        {
            string code = HttpContext.Session.GetString("code");
            return service.getUserMsg(code);
        }
        [HttpGet]
        public Dictionary<string, object> logout()
        {
            HttpContext.Session.Clear();
            return MyUtils.getSuccessDic("login.html");
        }
        public record loginModel(string username)
        {
            public string password { get; set; }
        }

    }
}
